Skip to content

ogma-core: Allow for inputs to be deeply nested fields in ROS 2 template. Refs #547. - #550

Merged
ivanperez-keera merged 2 commits into
nasa:developfrom
ivanperez-keera:develop-ros-subfields
Aug 25, 2026
Merged

ogma-core: Allow for inputs to be deeply nested fields in ROS 2 template. Refs #547.#550
ivanperez-keera merged 2 commits into
nasa:developfrom
ivanperez-keera:develop-ros-subfields

Conversation

@ivanperez-keera

@ivanperez-keera ivanperez-keera commented Aug 20, 2026

Copy link
Copy Markdown
Member

Modify the default ROS 2 template so that the test node generated uses variable names that do not include the sub-field name, as prescribed in the solution proposed for #547.

@nasa nasa deleted a comment from philphauler Aug 23, 2026
@ivanperez-keera
ivanperez-keera force-pushed the develop-ros-subfields branch 3 times, most recently from df0e450 to 123f321 Compare August 25, 2026 01:50
…bfields. Refs nasa#547.

The default ROS 2 template does not handle random value generation
correctly in the auto-generated test package when subfields are used.

For example, if an input variable `input_signal` is supposed to denote a
field `pose.pose.position.x` of an input message, the code generated in
the tests includes the invalid variable declaration:

```C++
double input_signal_pose.pose.position.x = randomFloat();
```

This commit modifies the default ROS 2 template so that the test node
generated uses variable names that do not include the sub-field name,
and thus do not result in code that does not compile if variables are
populated from message sub-fields.
@ivanperez-keera

Copy link
Copy Markdown
Member Author

Change Manager: Verified that:

  • Solution is implemented:
    • The code proposed compiles and passes all tests. Details:
    • The solution proposed produces the expected result. Details:
      The following Dockerfile uses Ogma to generate a ROS 2 monitor that depends a value of a subfield of an incoming message, and checks that the generated package builds correctly:
      --- Dockerfile-verify-547
      FROM ubuntu:26.04
      
      ENV DEBIAN_FRONTEND=noninteractive
      
      RUN apt-get update
      SHELL ["/bin/bash", "-c"]
      
      RUN apt-get install --yes --no-install-recommends \
        ca-certificates \
        curl \
        g++ \
        gcc \
        git \
        libbz2-dev \
        libexpat-dev \
        libgmp3-dev \
        libz-dev \
        make \
        pkg-config
      
      RUN mkdir -p $HOME/.local/bin
      ENV PATH=$PATH:/root/.local/bin/
      
      RUN curl https://downloads.haskell.org/~ghcup/0.2.6.2/x86_64-linux-ghcup-0.2.6.2 -o $HOME/.local/bin/ghcup
      RUN chmod a+x $HOME/.local/bin/ghcup
      
      ENV PATH=$PATH:/root/.ghcup/bin/
      RUN ghcup install ghc 9.12
      RUN ghcup install cabal 3.16
      RUN ghcup set ghc 9.12.4
      
      RUN cabal update
      
      RUN cabal install --lib copilot copilot-c99 copilot-language copilot-theorem \
               copilot-libraries copilot-interpreter
      
      ARG GIT_COMMIT=HEAD
      ARG NAME=ogma
      ARG REPO=https://github.com/nasa/ogma
      
      RUN git clone ${REPO} ${NAME}
      RUN cd ${NAME} && git checkout ${GIT_COMMIT}
      
      WORKDIR ${NAME}
      RUN cabal install ogma-cli:ogma
      
      ADD project.ogma /tmp
      ADD document-nav2-msgs.json /tmp
      ADD extra-vars-nav2-msgs.json /tmp
      ADD json-format-nav2-msgs.cfg /tmp
      ADD variables-nav2-msgs /tmp
      ADD vars-db-nav2-msgs.json /tmp
      ADD manual-deps.repos /tmp
      ADD manually-installed-pkgs.txt /tmp
      
      CMD ogma ros --project /tmp/project.ogma && \
          cd nav2-msgs-demo/copilot/src && \
          runhaskell Copilot.hs && \
          cd ../.. && \
          cp /tmp/manual-deps.repos . && \
          cp /tmp/manually-installed-pkgs.txt .
      
      --- project.ogma
      {
        "projectName": "Nav2 messages demo",
        "projectInputFiles": [
          [
            "/tmp/document-nav2-msgs.json",
            "/tmp/json-format-nav2-msgs.cfg",
            "literal"
          ]
        ],
        "projectVariableFiles": "/tmp/variables-nav2-msgs",
        "projectVariableDBFile": "/tmp/vars-db-nav2-msgs.json",
        "projectHandlerFile": null,
        "projectCommandPropVia": null,
        "projectTemplateDir": null,
        "projectTargetDir": "nav2-msgs-demo",
        "projectExtraJSONFile": "/tmp/extra-vars-nav2-msgs.json"
      }
      
      --- document-nav2-msgs.json
      {
        "Nav2Copilot": {
          "internal_variables": [],
          "external_variables": [
            { "name":"input_signal", "type":"Double", "meaning": "InputF64" }
          ],
          "properties": [
            { "id":      "KeepInCheck",
              "formula": "input_signal >= 1 && input_signal < 10",
              "text":    "The vehicle stays near the central column"
            }
          ]
        }
      }
      
      --- extra-vars-nav2-msgs.json
      { "target_extra_dependencies":
          [ "nav2_msgs"
          ]
      , "package_extra_depend":
          [ "nav2_msgs"
          ]
      , "impl_extra_header":
          [ "#include \"nav_msgs/msg/odometry.hpp\"" ]
      }
      
      --- json-format-nav2-msgs.cfg
      JSONFormat
         { specInternalVars          = Just "..internal_variables[*]"
         , specInternalVarId         = ".name"
         , specInternalVarExpr       = ".meaning"
         , specInternalVarType       = Just ".type"
         , specExternalVars          = Just "..external_variables[*]"
         , specExternalVarId         = ".name"
         , specExternalVarType       = Just ".type"
         , specRequirements          = "..properties[*]"
         , specRequirementId         = ".id"
         , specRequirementDesc       = Just ".text"
         , specRequirementExpr       = ".formula"
         , specRequirementResultType = Nothing
         , specRequirementResultExpr = Nothing
         }
      
      --- variables-nav2-msgs
      input_signal
      
      --- vars-db-nav2-msgs.json
      { "inputs":
           [ { "name": "input_signal"
             , "type": "double"
             , "active": true
             , "connections":
                 [ { "scope": "ros/message"
                   , "topic": "/model/vehicle/odometry"
                   , "field": "pose.pose.position.x"
                   }
                 ]
             }
           ]
      , "topics":
           [ { "scope": "ros/message"
             , "topic": "/model/vehicle/odometry"
             , "type":  "nav_msgs::msg::Odometry"
             }
           ]
      , "types": [
             { "fromScope": "ros/message"
             , "fromType":  "nav_msgs::msg::Odometry"
             , "fromField": "pose.pose.position.x"
             , "toScope":   "C"
             , "toType":    "double"
             }
           ]
      }
      
      --- manual-deps.repos
      repositories:
        navigation2:
          type: git
          url: https://github.com/ros-planning/navigation2.git
          version: jazzy
        geographic_info:
          type: git
          url: https://github.com/ros-geographic-info/geographic_info.git
          version: jazzy
      
      --- manually-installed-pkgs.txt
      geographic_msgs
      nav2_common
      nav2_msgs
      
      Command (substitute variables based on new path after merge):
      $ docker build --build-arg "REPO=https://github.com/ivanperez-keera/ogma" --build-arg "NAME=ogma" --build-arg "GIT_COMMIT=4124c4fc828a82a90443c03865980adeb31ec842" -t ogma-verify-547 -f Dockerfile-verify-547 .
      $ docker run -v $PWD/nav2-msgs-demo:/ogma/nav2-msgs-demo -it ogma-verify-547
      $ cd nav2-msgs-demo
      $ docker build -t ogma-verify-547-space-ros .
      
  • Implementation is documented. Details:
    No updates needed; change is a minor change to the template.
  • Change history is clear.
  • Commit messages are clear.
  • Changelogs are updated.
  • Examples are updated. Details:
    No updates needed; change does not affect existing examples.
  • Author is internal or has provided signed CLA.
  • Required version bumps are evaluated. Details:
    Bump not needed; change makes existing template work for more cases but does not alter previously working applications.

@ivanperez-keera
ivanperez-keera merged commit 622cd60 into nasa:develop Aug 25, 2026
7 checks passed
@ivanperez-keera
ivanperez-keera deleted the develop-ros-subfields branch August 25, 2026 14:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant